<%@ page language="java" import="java.util.*,com.tjsinfo.tjsoa.system.vo.TjsRoles,com.tjsinfo.tjsoa.system.vo.TSystemRolesGroup,java.util.Map.Entry" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Map<String, List<TjsRoles>> parentMenuMap =(Map)request.getAttribute("parentMenuMap");
int roleSize=(Integer)request.getAttribute("roleSize");
List<TSystemRolesGroup> groupList=(List)request.getAttribute("rolesGroupList");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>粮油集团办公自动化协作平台</title>
<link href="<%=basePath %>style/txlk7.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath %>ajaxFramework/jQuery/jquery.js"></script>
<script src="<%=basePath%>js/common/move/move.js" type=text/javascript></script>


<script src="<%=basePath%>js/common/move/idrag.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/idrop.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/iutil.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/iresizable.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/ifxtransfer.js" type=text/javascript></script>

<link rel="stylesheet" type="text/css" href="<%=basePath%>ajaxFramework/ext-2.1/resources/css/ext-all.css" />
<script type="text/javascript" src="<%=basePath%>ajaxFramework/ext-2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<%=basePath%>ajaxFramework/ext-2.1/ext-all.js"></script>
<script type="text/javascript" src="<%=basePath%>ajaxFramework/ext-2.1/examples.js"></script>
	
	
<style type=text/css media=all>
.zxzx ul{
margin-left:8px;margin-right:8px;width:100%}
.zxzx li{
float:left; width:150px;line-height:28px; display:block; color:#0E3451;text-align: left;
}



#container {
    width:600px;
    height:300px;
    border:3px solid #c3daf9;
}
#window {
	DISPLAY: none;
	LEFT: 200px;
	OVERFLOW: hidden;
	WIDTH: 600px;
	POSITION: absolute;
	TOP: 100px;
	HEIGHT: 200px
}

#windowTop {
	BACKGROUND-POSITION: right top;
	BACKGROUND-IMAGE: url(<%=basePath%>js/common/move/images/window_top_end.png);
	OVERFLOW: hidden;
	CURSOR: move;
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 30px
}

#windowTopContent {
	BACKGROUND-POSITION: left top;
	FONT-WEIGHT: bold;
	FONT-SIZE: 14px;
	BACKGROUND-IMAGE: url(<%=basePath%>js/common/move/images/window_top_start.png)
		;
	OVERFLOW: hidden;
	COLOR: #206D85;
	TEXT-INDENT: 10px;
	LINE-HEIGHT: 30px;
	MARGIN-RIGHT: 13px;
	BACKGROUND-REPEAT: no-repeat;
	FONT-FAMILY: Arial, Helvetica, sans-serif;
	HEIGHT: 30px
}

#windowMin {
	RIGHT: 25px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowMax {
	DISPLAY: none;
	RIGHT: 25px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowClose {
	RIGHT: 10px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowBottom {
	BACKGROUND-POSITION: right bottom;
	BACKGROUND-IMAGE:
		url(<%=basePath%>js/common/move/images/window_bottom_end.png);
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 170px
}

#windowBottomContent {
	BACKGROUND-POSITION: left bottom;
	BACKGROUND-IMAGE:
		url(<%=basePath%>js/common/move/images/window_bottom_start.png);
	MARGIN-RIGHT: 13px;
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 170px
}

#windowResize {
	RIGHT: 3px;
	CURSOR: se-resize;
	BOTTOM: 5px;
	POSITION: absolute
}

#windowContent {
	BORDER-RIGHT: #6caf00 1px solid;
	BORDER-TOP: #6caf00 1px solid;
	FONT-SIZE: 11px;
	LEFT: 10px;
	OVERFLOW: auto;
	BORDER-LEFT: #6caf00 1px solid;
	WIDTH: 575px;
	MARGIN-RIGHT: 10px;
	BORDER-BOTTOM: #6caf00 1px solid;
	FONT-FAMILY: Arial, Helvetica, sans-serif;
	POSITION: absolute;
	TOP: 30px;
	HEIGHT: 155px;
	BACKGROUND-COLOR: #fff
}
#zx {
	HEIGHT: 145px;
	OVERFLOW: auto;
	height: 95%;
}

.transferer2 {
	BORDER-RIGHT: #6baf04 1px solid;
	BORDER-TOP: #6baf04 1px solid;
	FILTER: alpha(opacity =       30);
	BORDER-LEFT: #6baf04 1px solid;
	BORDER-BOTTOM: #6baf04 1px solid;
	BACKGROUND-COLOR: #b4f155;
	-moz-opacity: 0.3;
	opacity: 0.3
}
</style>
		
<script type="text/javascript">
function selectCheckRole(tagName){
    var a=document.getElementsByName(tagName);   
    var roles=',';//当前选中权限
    for(var i=0; i<a.length; i++)  { 
    	if(a[i].checked)roles=roles+a[i].value.slice(1);
    }
	if(confirm('您确认当前所选权限?')){
		if(isEmpty(document.getElementById("nowSelectGroupName").value) ){
			alert('您当前没有组被选中!');
		}else{
			document.getElementById('selectGroupId').value=roles;
			permissionUpdate.submit();
		}
	}
}
function setCheckRole(strList){
	var a=document.getElementsByName('checkId');   
    for(var i=0; i<a.length; i++)  { 
    	a[i].checked=false;
    } 
	var roleId=strList.split(",");
	for(var i=1;i<roleId.length;i++){
		if(document.getElementById('checkId,'+roleId[i]+",")!=null)document.getElementById('checkId,'+roleId[i]+",").checked=true;
	}
}
function clearCheckRole(strList){
	var a=document.getElementsByName('checkId');   
    for(var i=0; i<a.length; i++)  { 
    	a[i].checked=false;
    }
}
function isChinese(str){     
	//var badChar ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	//badChar += "abcdefghijklmnopqrstuvwxyz";
	//badChar += "0123456789";
	//badChar += " "+"　";//半角与全角空格
	var badChar = ".*`~!@#$%^&()-_=+]\\|:;\"\\'<,>?/";//不包含*或.的英文符号
	if(""==str){     
	return false;     
	}
	for(var i=0;i<str.length;i++){
		var c = str.charAt(i);
		if(badChar.indexOf(c) > -1){     
			return false;    
		}     
	}     
	return true;     
}
function groupOnclick(groupId,groupName){
	if(document.getElementById('nowSelectGroupId')!=null){
		var tempGroupId=document.getElementById('nowSelectGroupId').value;
		$("#li"+tempGroupId).html(document.getElementById('nowSelectGroupName').value);
	}
	//var tempGroupName;
	//if(document.getElementById('nowSelectGroupName')!=null)tempGroupId=document.getElementById('nowSelectGroupName').value;

	document.getElementById('nowSelectGroupId').value=groupId;
	document.getElementById('nowSelectGroupName').value=groupName;
	$("#li"+groupId).html("<b>"+groupName+"</b>");
}
function isEmpty(str){
	str=str.trim(str);
	if(str==null || str.length==0) return true;
	else 
	return false;
}
function DeleteCheckRole(){
	var str=document.getElementById('nowSelectGroupName').value;
	var id=document.getElementById('nowSelectGroupId').value;
	if(isEmpty(document.getElementById("nowSelectGroupName").value) ){ alert('您当前没有组被选中!'); return false;}
	if(confirm('你确认要删除'+str+'吗?\r删除后不能恢复.\r请慎重操作.')){
		window.location.href='<%=basePath %>tjsinfo/tjsoa/system/roleGroupManage.do?method=roleGroupDelete&id='+id;
	}
}
function CheckRole(){
    var str=document.getElementById('nowSelectGroupName').value;
	var id=document.getElementById('nowSelectGroupId').value;
	if(isEmpty(document.getElementById("nowSelectGroupName").value) ){ alert('您当前没有组被选中!'); return false;}
		window.location.href='<%=basePath %>tjsinfo/tjsoa/system/rolegroupuserlist.do?id='+id;
}
</script>
</head>

<body>
<div id="right">
<div style="height:92%">
      <div class="p_011">
		    <ul>
                <li class="s03"><a href="javascript:clearCheckRole();">清空</a></li>
                <li class="s03"><a href="javascript:selectCheckRole('checkId');">保存</a></li>
                <li class="s03"><a id="windowOpen" href="javascript:setCheckRole(',');">添加</a></li>
                <li class="s03"><a onclick="javascript:DeleteCheckRole();" style="cursor: hand">删除</a></li>
                <li class="s03"><a onclick="javascript:CheckRole();" style="cursor: hand;">查看</a></li>
            </ul>
	  </div>
	  <form action="<%=basePath %>tjsinfo/tjsoa/system/roleGroupManage.do?method=roleGroupUpdate" name="permissionUpdate" method="post">
	  <input id="nowSelectGroupName" type="hidden" value=""/><input id="nowSelectGroupId" name="nowSelectGroupId" type="hidden" value=""/>
	  <input id="selectGroupId" name="selectGroupId" type="hidden" value=""/>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
          <tr>
            <td width="15%" valign="top" align="left" height="100%">
              <div class="conrenqx">
				<div class="h"><table width="99%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="20%" align="center"><img src="<%=basePath %>images/949_03.gif" /></td>
                        <td align="left">权限组</td>
                      </tr>
                    </table>
                </div>
                <div style="width:161px;overflow-y:auto; overflow-x:auto" id="leftdiv">
                  	<ul>
                  	<%for(TSystemRolesGroup trg:groupList){ %>
                      <li><a id="li<%=trg.getId() %>" href="javascript:setCheckRole('<%=trg.getPermission() %>');groupOnclick('<%=trg.getId() %>','<%=trg.getGroupname() %>');" ><%=trg.getGroupname() %></a></li>
                      <%} %>
                    </ul>
                </div>
              </div>
            </td>
            <td width="85%" valign="top" height="100%">
               <div class="contab100" id="maindiv">
                   <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center">
                       <table width="97%" border="0" cellspacing="0" cellpadding="0" style="margin-top:14px">
                       <%
						Set<Entry<String, List<TjsRoles>>> params = parentMenuMap.entrySet();
						for (Map.Entry entry : params) {//遍历父栏目
							List<TjsRoles> value=(List)entry.getValue();//遍历子栏目,将子栏目填入到父栏目中
							String key=(String)entry.getKey();
						%>
						<tr>
                            <td align="left">
                                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <th style="border-bottom:1px #BABABB dashed;color:#0E3451;text-align: left">&nbsp;<img src="<%=basePath %>images/cgxicon.gif" />&nbsp;&nbsp;<%out.print(key); %></th>
                                  </tr>
                                  <tr>
                                    <td>&nbsp;</td>
                                  </tr>
                                  <tr>
                                    <td align="center">
                                     <div class="zxzx">
                                          <ul>
                                          <%for(int i=0;i<value.size();i++){
                                          TjsRoles role=value.get(i);
                                          //if(i%7==0)out.print("</ul><ul>");
                                          %>
                                              <li><input id="checkId<%out.print(role.getRoleId()); %>" type="checkbox" name="checkId" value="<%out.print(role.getRoleId()); %>" />&nbsp;<%out.print(role.getName()); %></li>
                                          <%} %>
                                          </ul>
                                      </div>
                                    </td>
                                  </tr>
                                </table>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
						<%}%>
                        </table>
                    </td>
                  </tr>
              </table>
              </div>
            </td>
          </tr>
      </table></form>
</div>
</div>
<div id=window>
			<div id=windowTop>
				<div id=windowTopContent>
					添加权限组
				</div>
				<img id=windowMax src="<%=basePath%>js/common/move/images/window_max.jpg" />
				<img id=windowClose
					src="<%=basePath%>js/common/move/images/window_close.jpg" />
			</div>
			<div id=windowBottom>
				<div id=windowBottomContent></div>
			</div>
			<div id="windowContent" style="background: #D9E8F1">
				<div style="padding-top: 20px; padding-left: 20px;">
					<form action="<%=basePath%>tjsinfo/tjsoa/system/roleGroupManage.do?method=roleGroupSave" id="formQuery" name="formQuery" method="post">
						<table width="90%" border="0" cellspacing="0"
							cellpadding="0" class="researchtab">
							<tr>
								<td width="30%" align="right">
									权限组名称：
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="groupName" id="groupName" type="text" size="48" class="textinput" maxlength="6"/>
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
									排列序号：
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="groupNo" id="groupNo" type="text" size="48" class="textinput" maxlength="3"/>
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td height="10px;" colspan="6" align="center">
									<a id="sub" style="cursor: hand"><img src="<%=basePath%>images/qd.gif" /></a>&nbsp;&nbsp;&nbsp;&nbsp;
									<a id="resetSend" style="cursor: hand"><img src="<%=basePath%>images/qx.gif" /></a>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		<img id=windowResize
			src="<%=basePath%>js/common/move/images/window_resize.gif" />
</div>
		<script type=text/javascript>
	$(document).ready(function()
	{
		document.getElementById("leftdiv").style.height = document.body.clientHeight-88;
		document.getElementById("maindiv").style.height = document.body.clientHeight-60;
		$('#windowOpen').bind(
			'click',
			function() {
				if($('#window').css('display') == 'none') {
					$(this).TransferTo(
						{
							to:'window',
							className:'transferer2', 
							duration: 400,
							complete: function()
							{
								$('#window').show();
							}
						}
					);
					$('#selectPage').hide();
				}
				this.blur();
				return false;
			}
		);
		$('#windowClose').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2', 
						duration: 400
					}
				).hide();
				$('#selectPage').show();
			}
		);
		$('#resetSend').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2', 
						duration: 400
					}
				).hide();
				$('#selectPage').show();
			}
		);
		$('#windowMin').bind(
			'click',
			function()
			{
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
				$('#window').animate({height:40},300).get(0).isMinimized = true;
				$(this).hide();
				$('#windowResize').hide();
				$('#windowMax').show();
			}
		);
		$('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
				$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
				$(this).hide();
				$('#windowMin, #windowResize').show();
			}
		);
		$('#window').Resizable(
			{
				minWidth: 200,
				minHeight: 60,
				maxWidth: 700,
				maxHeight: 400,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
					var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
					if (!document.getElementById('window').isMinimized) {
						windowContentEl.css('height', size.height - 48 + 'px');
					}
				}
			}
		);
		$('#sub').bind(
			'click',
			function()
			{
				var pattern = /^[1-9]\d*$/;
				if(!pattern.test(document.getElementById("groupNo").value)){alert("序号应为数字！"); return false;} 
			    if(isEmpty(document.getElementById("groupName").value) ){ alert('请输入权限组名称!'); return false;}
			    if(!isChinese(document.getElementById("groupName").value)){alert('权限组名称不能为字符!'); return false;}
				document.formQuery.submit();
			}
		);
		
		<%if(request.getAttribute("roleGroup")!=null){
			TSystemRolesGroup trg=(TSystemRolesGroup)request.getAttribute("roleGroup");
		%>
			setCheckRole('<%=trg.getPermission() %>');
			var htmls=$("#li"+<%=trg.getId() %>).html();
			$("#li"+<%=trg.getId() %>).html("<b>"+htmls+"</b>");
			
			document.getElementById('nowSelectGroupId').value='<%=trg.getId() %>';
			document.getElementById('nowSelectGroupName').value='<%=trg.getGroupname() %>';
		<%}%>
		
		<%if(request.getAttribute("alert")!=null){%>
		alert('<%=(String)request.getAttribute("alert") %>');
		<%}%>
	}
);
</script>
</body>
</html>
